import { bachSaveApi } from "@/api/waybillManagement/customerServiceWaybill/index";
import dayjs from "dayjs";
import { message } from "ant-design-vue";

export default function OperationHook(state: any) {
  const { formState, formDataRef, emit, passData } = state;

  const onSubmit = () => {
    const params = {
      ...formState,
      waybillNums: passData.value.map((t: any) => t.waybillNum)
    };

    if (params.content.length > 1) return message.error("只支持一个节点名称");
    params.content = params.content.join();
    if (params.nodeTime) params.nodeTime = dayjs(formState.nodeTime).format("YYYY-MM-DD HH:mm:ss");
    bachSaveApi(params).then((res: any) => {
      const { code } = res;
      if (code === 200) {
        message.success("操作成功!");
        formDataRef.value.resetFields();
        emit("submit");
      }
    });
  };
  const resetForm = () => {
    formDataRef.value.resetFields();
    emit("update:visible", false);
  };
  return {
    resetForm,
    onSubmit
  };
}
